package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;
    /**
     * 文件上传
     * @param username
     * @param age
     * @param image
     * @return
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {
        log.info("文件上传，参数：{}",image);

        //利用阿里云OSS工具类将文件上传至阿里云服务器
        String url = aliOSSUtils.upload(image);

        //将图片上传完成后的url返回，用于浏览器回显展示
        return Result.success(url);
    }
}
